Skip to content

[FLINK-38846][mysql] Optimize LinkedList processing in handleChange method to reduce complexity#4250

Merged
lvyanquan merged 2 commits into
apache:masterfrom
Hisoka-X:FLINK-38846-mysql-linkedlist
Feb 3, 2026
Merged

[FLINK-38846][mysql] Optimize LinkedList processing in handleChange method to reduce complexity#4250
lvyanquan merged 2 commits into
apache:masterfrom
Hisoka-X:FLINK-38846-mysql-linkedlist

Conversation

@Hisoka-X
Copy link
Copy Markdown
Member

This close https://issues.apache.org/jira/browse/FLINK-38846

This pull request optimizes the processing of row events in the MySQL and OceanBase CDC connectors by replacing an index-based loop with an iterator-based loop in the handleChange method. This change improves performance when handling LinkedList row collections, reducing time complexity from O(n²) to O(n).

@lvyanquan
Copy link
Copy Markdown
Contributor

I'm unclear how the O(n²) time complexity arises—could you elaborate on the specific cause?

@Hisoka-X
Copy link
Copy Markdown
Member Author

Hisoka-X commented Feb 3, 2026

I'm unclear how the O(n²) time complexity arises—could you elaborate on the specific cause?

As ticket say, the BinaryLogClient return LinkedList. But MySqlStreamingChangeEventSource handleChange() uses Index-based for loop traversal

https://github.com/apache/flink-cdc/blob/master/flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/io/debezium/connector/mysql/MySqlStreamingChangeEventSource.java#L947

So the cost is
O(1 + 2 + 3 + ... + n)
= O(n²)

Copy link
Copy Markdown
Contributor

@lvyanquan lvyanquan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@lvyanquan lvyanquan merged commit 7f2fd1f into apache:master Feb 3, 2026
15 checks passed
@Hisoka-X Hisoka-X deleted the FLINK-38846-mysql-linkedlist branch February 3, 2026 03:22
ThorneANN pushed a commit to ThorneANN/flink-cdc that referenced this pull request Mar 19, 2026
Mrart pushed a commit to Mrart/flink-cdc that referenced this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants